﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Data;
using System.Data.SqlClient;


namespace 李晓霞web
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void txtPwd_TextChanged(object sender, EventArgs e)
        {

        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "广东省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("揭阳");
                DropDownList2.Items.Add("潮州");
                DropDownList2.Items.Add("深圳");
                DropDownList2.Items.Add("广州");
                DropDownList2.Items.Add("惠州");
            }
            else if (DropDownList1.SelectedValue == "湖南省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("长沙");
                DropDownList2.Items.Add("株洲");

            }
            else if (DropDownList1.SelectedValue == "海南省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("海口");
                DropDownList2.Items.Add("三亚");

            }
            else if (DropDownList1.SelectedValue == "内蒙古自治区")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("呼和浩特");
                DropDownList2.Items.Add("包头");


            }
            else if (DropDownList1.SelectedValue == "浙江省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("杭州");
                DropDownList2.Items.Add("宁波");
                DropDownList2.Items.Add("嘉兴");
                DropDownList2.Items.Add("绍兴");

            }
            else if (DropDownList1.SelectedValue == "安徽省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("合肥");
                DropDownList2.Items.Add("芜湖");
                DropDownList2.Items.Add("马鞍山");

            }
            else if (DropDownList1.SelectedValue == "台湾省")
            {
                DropDownList2.Items.Clear();
                DropDownList2.Items.Add("台北");
                DropDownList2.Items.Add("高雄");
                DropDownList2.Items.Add("台南");
            }

            else
            {
                DropDownList2.Items.Clear();
            }


        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void btnRegisrer_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112106;uid=2014112106;password=19950616";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                if (this.rdoStudent.Checked)
                {
                    cn.Open();
                    string strUserName = this.txtUserName.Text;
                    string strUserPwd = this.txtPwd.Text;
                  
                    string strEmail = this.txtEmail.Text;
                    string strAddress = this.DropDownList1.Text  + this.DropDownList2.Text ;

                    string Gender = Request.QueryString["Gender"];
                    if (rdoM.Checked)
                    {
                        Gender = "男";
                    }
                    else
                    {
                        Gender = "女";
                    }

                    string strSql = "INSERT INTO StudentRegister (UserName,Password,Gender,Email,Address) VALUES   (N'" + strUserName + "', N'" + strUserPwd + "',N'" + Gender + "',N'" + strEmail + "',N'" + strAddress + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        this.lblInfo.Text = "注册失败！";
                    }
                    else
                    {
                        this.lblInfo.Text = "注册成功！";
                    }

                    Response.Write("<script>alert('账户注册成功！点击登录试试！');</script>");
                }
                else
                {
                    if (this.rdoTeacher.Checked)
                    {
                        cn.Open();
                        string strUserName = this.txtUserName.Text;
                        string strUserPwd = this.txtPwd.Text;
                      
                        string strEmail = this.txtEmail.Text;
                        string strAddress = this.DropDownList1.SelectedValue + this.DropDownList2.SelectedValue;

                        string Gender = Request.QueryString["Gender"];
                        if (rdoM.Checked)
                        {
                            Gender = "男";
                        }
                        else
                        {
                            Gender = "女";
                        }

                        string strSql = "INSERT INTO TeacherRegister (UserName,Password,Gender,Email,Address) VALUES   (N'" + strUserName + "', N'" + strUserPwd + "',N'" + Gender + "',N'" + strEmail + "',N'" + strAddress + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        int iUpd = cmd.ExecuteNonQuery();
                        if (iUpd < 1)
                        {
                            this.lblInfo.Text = "注册失败！";
                        }
                        else
                        {
                            this.lblInfo.Text = "注册成功！";
                        }

                        Response.Write("<script>alert('账户注册成功！点击登录试试！');</script>");
                    }
                }

            }

            catch(Exception ex)
            {

                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }

        }

        protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
        {

        }
    }
}